function heights = findHeights(P1,P2,N)

load('triangles.mat');
load('gridStructure.mat');

heights = [];
for i=0:N
   curP = (i*P1 + (N-i)*P2)/N;
   
   triangleIndex = searchTriangle(curP,sites,triangles,1,gridStructure);
   
   if(triangleIndex==0)
        disp('triangle not found');
   else
        nodeA = sites(triangles(triangleIndex,1),:);
        nodeB = sites(triangles(triangleIndex,2),:);
        nodeC = sites(triangles(triangleIndex,3),:);
        
        T = [nodeA; nodeB; nodeC];
        A = det([ones(3,1) T(:,2:3)]);
        B = det([T(:,1) ones(3,1) T(:,3)]);
        C = det([T(:,1:2) ones(3,1)]);
        D = -det([T(:,1:3)]);

        z = (-D-A*curP(1)-B*curP(2))/C;
        heights = [heights; z];
   end
end

end